--------------------------------------------------------------------------------------------------
      name:  <unnamed>
       log:  /Users/pabloguzmanpinto/Dropbox/PAME 3ie/Do-files/Logs/8_Tables_prepare.log
  log type:  text
 opened on:  14 Dec 2015, 15:30:39

. 
. use "${path_data}/variables2010_2011_2013.dta", clear

. 
. // Variable for business training projects
. quiet egen project=group(adm_codigo_p), missing 

. 
. keep if TT!=. /* GC, PAME2, y Fin. Adic.*/
(1382 observations deleted)

. 
. 
. // Merge to retrieve data about municipality of project
. sort id2011

. merge 1:1 id2011 using "${path_data}/base_comuna.dta", generate(m_comuna)

    Result                           # of obs.
    -----------------------------------------
    not matched                           730
        from master                         0  (m_comuna==1)
        from using                        730  (m_comuna==2)

    matched                             1,948  (m_comuna==3)
    -----------------------------------------

. drop m_comuna

. 
. encode comuna, gen(comu)

. 
. // Cut points for Social Security Card score
. scalar corte1= 2168

. scalar corte2= 2298.5

. scalar corte3= 3445     

. 
. // Brackets for Social Security Card Score
. gen fichaps1=0 if fichaps2011!=.
(788 missing values generated)

. gen fichaps2=0 if fichaps2011!=.
(788 missing values generated)

. gen fichaps3=0 if fichaps2011!=.
(788 missing values generated)

. gen fichaps4=0 if fichaps2011!=.
(788 missing values generated)

. replace fichaps1=(fichaps2011 <=corte1) if fichaps2011!=.
(470 real changes made)

. replace fichaps2=(corte1<fichaps2011 & fichaps2011 <=corte2) if fichaps2011!=. 
(467 real changes made)

. replace fichaps3=(corte2<fichaps2011 & fichaps2011 <=corte3) if fichaps2011!=. 
(478 real changes made)

. replace fichaps4=(corte3<fichaps2011) if fichaps2011!=.
(475 real changes made)

. 
. 
. *** Strata
. ** Each municipality is divided into 4 groups, according to Social Security Card score brackets
. local i=1

.         while `i'<=27 {
  2.                 gen d`i'1=0
  3.                 gen d`i'2=0
  4.                 gen d`i'3=0
  5.                 gen d`i'4=0
  6.                 replace d`i'1=1 if comu==`i' & fichaps1==1
  7.                 replace d`i'2=1 if comu==`i' & fichaps2==1
  8.                 replace d`i'3=1 if comu==`i' & fichaps3==1
  9.                 replace d`i'4=1 if comu==`i' & fichaps4==1
 10.                 
.         local i=`i'+1
 11.         }
(2 real changes made)
(6 real changes made)
(6 real changes made)
(6 real changes made)
(28 real changes made)
(8 real changes made)
(6 real changes made)
(12 real changes made)
(4 real changes made)
(9 real changes made)
(16 real changes made)
(20 real changes made)
(3 real changes made)
(1 real change made)
(3 real changes made)
(4 real changes made)
(7 real changes made)
(10 real changes made)
(11 real changes made)
(13 real changes made)
(13 real changes made)
(12 real changes made)
(9 real changes made)
(3 real changes made)
(2 real changes made)
(11 real changes made)
(18 real changes made)
(10 real changes made)
(6 real changes made)
(4 real changes made)
(10 real changes made)
(8 real changes made)
(23 real changes made)
(43 real changes made)
(22 real changes made)
(7 real changes made)
(13 real changes made)
(26 real changes made)
(30 real changes made)
(30 real changes made)
(26 real changes made)
(37 real changes made)
(29 real changes made)
(34 real changes made)
(47 real changes made)
(29 real changes made)
(16 real changes made)
(17 real changes made)
(16 real changes made)
(9 real changes made)
(24 real changes made)
(19 real changes made)
(11 real changes made)
(10 real changes made)
(10 real changes made)
(10 real changes made)
(5 real changes made)
(10 real changes made)
(16 real changes made)
(44 real changes made)
(35 real changes made)
(7 real changes made)
(25 real changes made)
(30 real changes made)
(46 real changes made)
(20 real changes made)
(18 real changes made)
(21 real changes made)
(31 real changes made)
(83 real changes made)
(49 real changes made)
(38 real changes made)
(30 real changes made)
(11 real changes made)
(19 real changes made)
(20 real changes made)
(36 real changes made)
(8 real changes made)
(7 real changes made)
(6 real changes made)
(19 real changes made)
(6 real changes made)
(16 real changes made)
(10 real changes made)
(14 real changes made)
(16 real changes made)
(30 real changes made)
(26 real changes made)
(18 real changes made)
(10 real changes made)
(10 real changes made)
(13 real changes made)
(3 real changes made)
(14 real changes made)
(17 real changes made)
(11 real changes made)
(5 real changes made)
(27 real changes made)
(41 real changes made)
(32 real changes made)
(23 real changes made)
(22 real changes made)
(3 real changes made)
(7 real changes made)
(4 real changes made)
(18 real changes made)
(17 real changes made)
(24 real changes made)

.         
. # delimit ;
delimiter now ;
. global estrato "d11 d12 d13 d14 
> d21 d22 d23 d24 
> d31 d32 d33 d34 
> d41 d42 d43 d44 
> d51 d52 d53 d54 
> d61 d62 d63 d64
> d71 d72 d73 d74 
> d81 d82 d83 d84 
> d91 d92 d93 d94 
> d101 d102 d103 d104 
> d111 d112 d113 d114 
> d121 d122 d123 d124
> d131 d132 d133 d134
> d141 d142 d143 d144
> d151 d152 d153 d154
> d161 d162 d163 d164
> d171 d172 d173 d174
> d181 d182 d183 d184
> d191 d192 d193 d194
> 
> d201 d202 d203 d204 
> d211 d212 d213 d214 
> d221 d222 d223 d224
> d231 d232 d233 d234
> d241 d242 d243 d244
> d251 d252 d253 d254
> d261 d262 d263 d264
> d271 d272 d273 d274 "
> ;

. # delimit cr
delimiter now cr
. 
. // Strata by municipality-project
. egen com_proj=group(comu project)
(730 missing values generated)

. 
. // Strata municipality-SSC score
. egen strata=group($estrato)

. label var strata "Strata municipality-SSC score"

. 
. save "${path_data}/variables2010_2011_2013_ready.dta", replace
file /Users/pabloguzmanpinto/Dropbox/PAME 3ie/Databases/variables2010_2011_2013_ready.dta saved

. 
. // ////////////////////////////////////////////////////////
. // ////////////////////////////////////////////////////////
. 
. log close
      name:  <unnamed>
       log:  /Users/pabloguzmanpinto/Dropbox/PAME 3ie/Do-files/Logs/8_Tables_prepare.log
  log type:  text
 closed on:  14 Dec 2015, 15:30:39
--------------------------------------------------------------------------------------------------
